<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=1000, initial-scale=1.0, maximum-scale=1.0">
	    <!-- Loading Bootstrap -->
	    <link href="__STATIC__/Admin/Flat/dist/css/vendor/bootstrap.min.css" rel="stylesheet">
	    <!-- Loading Flat UI -->
	    <link href="__STATIC__/Admin/Flat/dist/css/flat-ui.css" rel="stylesheet">
	    <link href="__STATIC__/Admin/Flat/docs/assets/css/demo.css" rel="stylesheet">

	    <link rel="shortcut icon" href="__STATIC__/Admin/Flat/img/favicon.ico">
	    <!-- HTML5 shim, for IE6-8 support of HTML5 elements. All other JS at the end of file. -->
	    <!--[if lt IE 9]>
	      <script src="dist/js/vendor/html5shiv.js"></script>
	      <script src="dist/js/vendor/respond.min.js"></script>
	    <![endif]-->
	    <!--百度编辑器载入的文件-->
		<script type="text/javascript" charset="utf-8" src="__STATIC__/ueditor1_4_3/ueditor.config.js"></script>
		<script type="text/javascript" charset="utf-8" src="__STATIC__/ueditor1_4_3/ueditor.all.min.js"> </script>
		<script type="text/javascript" charset="utf-8" src="__STATIC__/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
		<!--上传插件uploadify的文件-->
		<script type="text/javascript" src="__STATIC__/uploadify/jquery-1.8.2.min.js"></script>
		<script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
		<link href="__STATIC__/uploadify/uploadify.css" type="text/css" rel="stylesheet"></link>
		<script type="text/javascript" src="__STATIC__/Admin/js/goods.js"></script>

		<script type="text/javascript">
            // 全局变量
            var del_g = "{|U:'Goods/del_goods'}";
            var getAttr = "{|U:'Goods/getTypeAttr'}"; 

            var old_cid = "{$old_data.category_cid}";
            

            //让上传按钮显示
            function uploadifyShow(){
                     $('#file').uploadify({
                    'formData'     : {//POST数据
                        '<?php echo session_name();?>' : '<?php echo session_id();?>',
                    },
                    'fileTypeDesc' : '上传文件',//上传描述
                    'fileTypeExts' : '*.jpg;*.png',
                    'swf'      : '__STATIC__/uploadify/uploadify.swf',
                    'uploader' : '{|U:"upload"}',
                    'buttonText':'选择文件',
                    'fileSizeLimit' : '2000KB',
                    'uploadLimit' : 1,//上传文件数
                    'width':65,
                    'height':25,
                    'multi': false,//是否多文件上传
                    'successTimeout':10,//等待服务器响应时间
                    'removeTimeout' : 0.2,//成功显示时间
                    'onUploadSuccess' : function(file, data, response) {
                        //把变量转为json
                        data=$.parseJSON(data);
                        var li="<li path='"+data.path+"' url='"+data.url+"'><img src='"+data.url+"' style='width:200px;' class='img-thumbnail'/><a href='javascript:vaid(0);' class='del-img close'>X</a><input type='hidden' name='pic' value='"+data.path+"' /></li>";
                        $("#uploadList ul").prepend(li);
                        //让删除按钮消失
                        $('.uplodify-box').html('');
                    }
                });
            }
            

            $(function(){
                    //刷新页面让上传插件显示
                    uploadifyShow();
                    var ts = $(this);
                    //点击x，隐藏图片，并且上传按钮显示
                    $('.del-img').live('click',function(){
                        // 清空隐藏域里面的value值
                        var ts = $(this);
                        ts.siblings('input').val(''); 
                        //获得当前图片的所在的li，让其消失
                        $(this).parent('li').hide();
                        //上传按钮显示
                        $('.uplodify-box').html('<input id="file" type="file" multiple="false"><span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>');
                        uploadifyShow();　 
                        var pic_path = ts.parent().attr('path'); 
                        alert(pic_path);
                        del_ajax(pic_path);
                    }) 

                $('.close').click(function(){ 
                    var ts = $(this);
                    var pic_path = ts.attr('path');  
                    del_ajax(pic_path); 
                })  

            }); 
            //商品图册上传 让上传按钮显示
            function uploadifyPhoto(){
                     $('#file2').uploadify({
                    'formData'     : {//POST数据
                        '<?php echo session_name();?>' : '<?php echo session_id();?>',
                    },
                    'fileTypeDesc' : '上传文件',//上传描述
                    'fileTypeExts' : '*.jpg;*.png',
                    'swf'      : '__STATIC__/uploadify/uploadify.swf',
                    'uploader' : '{|U:"uploadPhoto"}',
                    'buttonText':'选择文件',
                    'fileSizeLimit' : '2000KB',
                    'uploadLimit' : 10,//上传文件数
                    'width':65,
                    'height':25,
                    'multi': true,//是否多文件上传
                    'successTimeout':10,//等待服务器响应时间
                    'removeTimeout' : 0.2,//成功显示时间
                    'onUploadSuccess' : function(file, data, response) {
                        //把变量转为json
                        data=$.parseJSON(data);
                        var li="<li path='"+data.path+"' url='"+data.url+"'><img src='"+data.url+"' style='' class='img-thumbnail'/><a href='javascript:;' class='del-img2 close'>X</a><input type='hidden' name='photo[]' value='"+data.path+"' /></li>";
                        $("#uploadList2 ul").prepend(li); 
                    }
                });
            }
            $(function(){
                    //刷新页面让上传插件显示
                    uploadifyPhoto();
                    //点击x，隐藏图片，并且上传按钮显示
                $('.del-img2').live('click',function(){ 
                    // 清空隐藏域里面的value值
                    var ts = $(this);
                    ts.siblings('input').val('');
                    //获得当前图片的所在的li，让其消失
                    $(this).parent('li').hide(); 
                    //上传按钮显示
                    $('.uplodify-box2').html('<input id="file2" type="file" multiple="false"><span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>');
                    uploadifyPhoto(); 
                    var pic_path = ts.parent().attr('path');  
                    del_ajax(pic_path);    
                }) 

                $('.close').click(function(){ 
                    var ts = $(this);
                    var pic_path = ts.attr('path');  
                    del_ajax(pic_path); 
                })


            }); 

        </script> 
        <style type="text/css">
        #uploadList{
            width: 600px; 
            overflow: hidden;
        }
        #uploadList2 ul,#uploadList2 ul li,#uploadList2 ul li,#uploadList2 ul li img{
            height:90px;
        } 
        #uploadList li,#uploadList2 li{
            width: 90px; 
            margin-right: 10px;
            list-style: none;
            position: relative;
        } 
        #uploadList2 li{
           float: left;
        } 

        #uploadList li img{
            width: 90px;  
        }  
        #uploadList li a,#uploadList2 li a{
            display: block;
            position: absolute;
            top:0px;
            right:0px; 
            width: 20px;
            height: 20px; 
            color: #f90;
        }  

        </style>

	</head>
	<body> 

		<div class="alert alert-success">编辑商品</div>
		<form action="" method="post">

		<div class="form-group">
			<label for="exampleInputEmail1">所属分类</label>
			<select name="category_cid" class="form-control">
				<option value="0">请选择</option>  
				<foreach from="$c_data" key="$k" value="$v">
					<option type_tid='{$v.type_tid}' value='{$v.cid}' <if value="$old_data['category_cid']==$v['cid']">selected</if>>{$v._name}</option>  
				</foreach> 

			</select>
		</div>

		<div class="form-group">
			<label for="exampleInputEmail1">所属品牌</label>
			<select name="brand_bid" class="form-control">
				<option value="0">请选择</option>
				<foreach from="$b_data" value="$v" key="$k">
					<option value="{$v.bid}" <if value="$old_data['brand_bid']==$v['bid']">selected</if>>{$v.bname}</option>
				</foreach>

			</select>
		</div>


		<div class="form-group">
			<label for="exampleInputEmail1">商品名称</label>
			<input id="exampleInputEmail1" class="form-control" type="text" placeholder="请输入商品名称"  name="gname" value="{$old_data.gname}">
		</div>

		<div class="form-group">
			<label for="exampleInputEmail1">单位</label>
			<input id="exampleInputEmail1" class="form-control" type="text" placeholder="请输入单位(件)"  name="unit" value="{$old_data.unit}">
		</div>

		<div class="form-group">
			<label for="exampleInputEmail1">市价场</label>
			<input id="exampleInputEmail1" class="form-control" type="text" placeholder="请输入市价场"  name="market_price" value="{$old_data.market_price}">
		</div>

		<div class="form-group">
			<label for="exampleInputEmail1">商城价</label>
			<input id="exampleInputEmail1" class="form-control" type="text" placeholder="请输入商城价"  name="goods_price" value="{$old_data.goods_price}">
		</div>

		<div class="form-group">
			<label for="exampleInputEmail1">点击次数</label>
			<input id="exampleInputEmail1" class="form-control" type="text" placeholder="请输入点击次数"  name="click" value="{$old_data.click}">
		</div>
 
            <div class="old_data">
			<p class="btn btn-primary">商品属性</p>
			<table class="table table-bordered table-hover" id='attr'>
                <foreach from="$attr_data" key="$k" value="$v">
                <tr class="info">
                    <td align="right">{$v.taname}</td>
                    <td>
                    <select class="form-control" name="attr[{$v.taid}]">
                        <option value="0">-请选择-</option>
                            
                            <foreach from="$v['tavalue']" key="$k" value="$v_v"> 

                                <option value="{$v_v}" <if value="in_array($v_v,$gav_data)">selected</if>>{$v_v}</option> 
                            </foreach> 

                    </select>
                    </td>
                </tr> 
                </foreach>
            </table>

			<p class="btn btn-primary">商品规格</p>
			<table class="table table-bordered table-hover" id='spec'>
                <foreach from="$new_c_p_date" key="$k_c_p" value="$v_c_p">  
                    <tr class="info">
                        <td align="right">颜色</td>
                        <td>
                            <input class="form-control" type="text" name="spec[{$spec_c_taid}][tavalue][]" value="{$v_c_p.color}">
                        </td>
                        <td>
                        <p style="float:left;">附加价格</p>
                            <input class="form-control" type="text" name="spec[{$spec_c_taid}][added][]" value="{$v_c_p.price}" style="float:left;width:40%;margin-left:5%;">
                        </td>
                        <td>　
                            <if value="$k_c_p==0" > 
                                <span class="btn btn-success add_spec"> <i class="icon-plus icon-white"></i>添加规格 </span>
                            <else/>  
                                <span class="btn btn-danger del_spec"> <i class="icon-white icon-minus"></i>删除规格</span>
                            </if>
                        </td>
                    </tr> 
                </foreach>

                <foreach from="$new_s_p_date" key="$k_s_p" value="$v_s_p">
                    <tr class="info">
                        <td align="right">{$spec_s_data.taname}</td>
                        <td>
                            <select class="form-control" name="spec[{$spec_s_taid}][tavalue][]">
                                <option value="0">-请选择-</option>
                                    <foreach from="$spec_s_data['tavalue']" key="$k" value="$v">
                                        <option value="{$v}" <if value="in_array($v,$v_s_p)">selected</if>>{$v}</option>
                                    </foreach>
                            </select>
                        </td>
                        <td>
                            <p style="float:left;">附加价格</p>
                            <input class="form-control" type="text" name="spec[{$spec_s_taid}][added][]" value="{$v_s_p.price}" style="float:left;width:40%;margin-left:5%;">
                        </td>
                        <td>
                            <if value="$k_s_p==0" > 
                                <span class="btn btn-success add_spec"> <i class="icon-plus icon-white"></i>添加规格 </span>
                            <else/>  
                                <span class="btn btn-danger del_spec"> <i class="icon-white icon-minus"></i>删除规格</span> 
                            </if> 

                        </td>
                    </tr>
                </foreach>
            </table>
            </div>

		
		<div class="form-group">
			<label for="exampleInputEmail1">列表图</label>  
			<div class='imgface_box'>  
            <div lab="uploadFile"> 
                <div class="uplodify-box"> 
                    <if value="!$old_data['pic']">
                        	<input id="file" type="file" multiple="false">
                            <span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
                    </if>
                </div>
                <div id="uploadList">
                    <ul> 
                            <if value="$old_data['pic']">
                                <li>
                                    <img src="__ROOT__/{$old_data.pic}" style="width:90px;" id="preview"/>
                                    <a href="javascript:vaid(0);" class="del-img close" path="{$old_data.pic}">X</a>

                                    <input type="hidden" value="{$old_data.pic}" name="pic">


                                </li>
                            </if> 
                    </ul>
                </div>
            </div>  
			</div> 

		</div>


		<div class="form-group">
			<label for="exampleInputEmail1">商品图册</label> 
			<div class='imgface_box'> 
                    <div lab="uploadFile"> 
                        <div class="uplodify-box2">  
                        	<input id="file2" type="file" multiple="true">
                            <span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span> 
                        </div>
                        <div id="uploadList2">
                            <ul> 
                                    <if value="$old_data['medium'][0]">
                                        <foreach from="$old_data['medium']" key="$k" value="$v">
                                        <li>
                                            <img src="__ROOT__/{$v}" style=""/>
                                            <a href="javascript:;" class="del-img2 close" path="{$v}">X</a>
                                            <input type='hidden' name='photo[]' value='{$v}' />
                                        </li>
                                        </foreach>
                                    </if> 
                            </ul>
                        </div>
                    </div>  
			</div>  
		</div> 
		
		<div class="form-group">
			<label for="exampleInputEmail1">商品详细</label> 
			<br />
			<script id="editor" type="text/plain" style="height:120px;" name="intro">{$old_data.intro}</script>
	    		<script>
	        		var ue = UE.getEditor('editor');
	    		</script>

		</div>

		<div class="form-group">
			<label for="exampleInputEmail1">售后服务</label> 
			<br />
			<script id="editor2" type="text/plain" style="height:120px;" name="service">{$old_data.service}</script>
	    		<script>
	        		var ue = UE.getEditor('editor2');
	    		</script>

		</div>

		<input type="hidden" name="type_tid" value="{$old_data.type_tid}">
        <input type="hidden" name="gid" value="{$old_data.gid}">
		<button class="btn btn-primary btn-block" type="submit"> 确定 </button>
		</form>
	</body>
</html> 